package demo1;

import java.util.*;

class Student {

}
public class Test {
    public static void main(String[] args) {
        Set<String> set = new TreeSet<>();
        set.add("asdf");
        set.add("t");
        set.add("s");
        System.out.println(set);
    }
    public static void main4(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("asd",23);
        treeMap.put("asd",67);
        System.out.println(treeMap);
    }
    public static void main3(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("asdf",3);
        treeMap.put("vd",90);
        System.out.println(treeMap.toString());
        Integer val = treeMap.get("vd");
        System.out.println(val);
        Integer val1 = treeMap.getOrDefault("aaa", 1000);
        System.out.println(val1);
        Integer a = treeMap.remove("asdf");
        System.out.println(a);
        treeMap.put("qwe",4);
        Set<String> keyset = treeMap.keySet(); // 获取全部key的值
        System.out.println(keyset);
        Collection<Integer> vals = treeMap.values();// 获取全部vals的值
        System.out.println(vals);
        Set<Map.Entry<String,Integer>> set = treeMap.entrySet(); // 映射 全部k - v 的值
        System.out.println(set);
        for (Map.Entry<String,Integer> entry: set) {  // 采用foreach的输出方式
            //System.out.print(entry + " ");
            System.out.println("key:" + entry.getKey() + "  value:" + entry.getValue());
        }
    }
    public static void main2(String[] args) {
        Map<Student,Integer> treeMap = new TreeMap<>();
        //key 一定是可以比较的
        treeMap.put(new Student(),2);
        treeMap.put(new Student(),3);
        System.out.println(treeMap);
    }
    public static void main1(String[] args) {
        Map<String,Integer> treeMap = new TreeMap<>();
        treeMap.put("vda",3);
        treeMap.put("bsa",7);
        treeMap.put("asdf",7);
        System.out.println(treeMap);
    }
}
